/*
 * Copyright (C) 2021 The Chinese Software International Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain an copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package com.socks.sample;

import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import static org.junit.Assert.assertEquals;

public class ExampleOhosTest {
    @Test
    public void testBundleName() {
        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
        assertEquals("com.socks.sample", actualBundleName);
    }

    @Test
    public void logDebug() {
        try {
            Class  mainAbilitySlice = Class.forName("com.socks.sample.slice.MainAbilitySlice");
            Method logDebug = mainAbilitySlice.getMethod("logDebug");
            Object obj = mainAbilitySlice.getConstructor().newInstance();
            logDebug.invoke(obj);
        } catch (ClassNotFoundException | NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void log() {
        try {
            Class  mainAbilitySlice = Class.forName("com.socks.sample.slice.MainAbilitySlice");
            Method log = mainAbilitySlice.getMethod("log");
            Object obj = mainAbilitySlice.getConstructor().newInstance();
            log.invoke(obj);
        } catch (ClassNotFoundException | NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void logWithNull() {
        try {
            Class  mainAbilitySlice = Class.forName("com.socks.sample.slice.MainAbilitySlice");
            Method logWithNull = mainAbilitySlice.getMethod("logWithNull");
            Object obj = mainAbilitySlice.getConstructor().newInstance();
            logWithNull.invoke(obj);
        } catch (ClassNotFoundException | NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void logWithMsg() {
        try {
            Class  mainAbilitySlice = Class.forName("com.socks.sample.slice.MainAbilitySlice");
            Method logWithMsg = mainAbilitySlice.getMethod("logWithMsg");
            Object obj = mainAbilitySlice.getConstructor().newInstance();
            logWithMsg.invoke(obj);
        } catch (ClassNotFoundException | NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void logWithTag() {
        try {
            Class  mainAbilitySlice = Class.forName("com.socks.sample.slice.MainAbilitySlice");
            Method logWithTag = mainAbilitySlice.getMethod("logWithTag");
            Object obj = mainAbilitySlice.getConstructor().newInstance();
            logWithTag.invoke(obj);
        } catch (ClassNotFoundException | NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }


    @Test
    public void logWithXml() {
        try {
            Class  mainAbilitySlice = Class.forName("com.socks.sample.slice.MainAbilitySlice");
            Method logWithXml = mainAbilitySlice.getMethod("logWithXml");
            Object obj = mainAbilitySlice.getConstructor().newInstance();
            logWithXml.invoke(obj);
        } catch (ClassNotFoundException | NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void logTraceStack() {
        try {
            Class  mainAbilitySlice = Class.forName("com.socks.sample.slice.MainAbilitySlice");
            Method logTraceStack = mainAbilitySlice.getMethod("logTraceStack");
            Object obj = mainAbilitySlice.getConstructor().newInstance();
            logTraceStack.invoke(obj);
        } catch (ClassNotFoundException | NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void logWithXmlFromNet() {
        try {
            Class  mainAbilitySlice = Class.forName("com.socks.sample.slice.MainAbilitySlice");
            Method logWithXmlFromNet = mainAbilitySlice.getMethod("logWithXmlFromNet");
            Object obj = mainAbilitySlice.getConstructor().newInstance();
            logWithXmlFromNet.invoke(obj);
        } catch (ClassNotFoundException | NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }


}
